package com.charging.business.enums;

/**
 * 车型信息
 *
 * @author JerryLu
 * @date 2024/9/26 10:11
 * @return
 */
public class Vtype {
    public static final int C1 = 1;
    public static final int C2 = 2;
    public static final int C3 = 3;
    public static final int C4 = 4;
    public static final int T1 = 11;
    public static final int T2 = 12;
    public static final int T3 = 13;
    public static final int T4 = 14;
    public static final int T5 = 15;
    public static final int T6 = 16;
    public static final int Z1 = 21;
    public static final int Z2 = 22;
    public static final int Z3 = 23;
    public static final int Z4 = 24;
    public static final int Z5 = 25;
    public static final int Z6 = 26;

    /**
     * 车型翻译
     */
    public static String trans(int vtype) {
        switch (vtype) {
            case C1:
                return "客1";
            case C2:
                return "客2";
            case C3:
                return "客3";
            case C4:
                return "客4";
            case T1:
                return "货1";
            case T2:
                return "货2";
            case T3:
                return "货3";
            case T4:
                return "货4";
            case T5:
                return "货5";
            case T6:
                return "货6";
            case Z1:
                return "专1";
            case Z2:
                return "专2";
            case Z3:
                return "专3";
            case Z4:
                return "专4";
            case Z5:
                return "专5";
            case Z6:
                return "专6";
        }
        return "未知车型";
    }

    /**
     * 判断是否是货车
     *
     * @param vtype
     * @return
     */
    public static boolean isTruck(int vtype) {
        return (vtype >= T1 && vtype <= T6) || (vtype >= Z1 && vtype <= Z6);
    }

    /**
     * 车型校验
     */
    public static boolean tstVType(int vtype, boolean allowTruck) {
        if (allowTruck) {// 允许货车操作
            return (vtype >= C1 && vtype <= C4) || (vtype >= T1 && vtype <= T6) || (vtype >= Z1 && vtype <= Z6);
        } else {// 不允许货车操作
            return vtype >= C1 && vtype <= C4;
        }
    }

    /**
     * 车型与轴数核查
     *
     * @return
     */
    public static boolean tstAxles(int vtype, int axles) {
        if (isTruck(vtype)) {// 为货车
            if ((vtype == T1 || vtype == Z1) && axles == 2) {
                return true;
            }
            if ((vtype == T2 || vtype == Z2) && axles == 2) {
                return true;
            }
            if ((vtype == T3 || vtype == Z3) && axles == 3) {
                return true;
            }
            if ((vtype == T4 || vtype == Z4) && axles == 4) {
                return true;
            }
            if ((vtype == T5 || vtype == Z5) && axles == 5) {
                return true;
            }
            return (vtype == T6 || vtype == Z6) && axles >= 6;
        } else {// 客车
            return axles >= 0 && axles <= 3;
        }
    }

    /**
     * 计费轴数计算
     *
     * @param vclass - 车种
     * @param vsign  - 车辆标识
     * @param vtype  - 车型
     * @param axles  - 轴数
     * @return - 计费轴数
     * 客车返回2
     * 普通货车及J1、J2集装箱最大返回6轴
     * 大件及甩挂车最大返回15轴
     */
    public static int feeAxles(int vclass, int vsign, int vtype, int axles) {
        int feeAxles = 2;
        if (vtype >= 11) {// 为货车
            feeAxles = axles;

            //轴数超限修正
            if (feeAxles > 15) {
                feeAxles = 15;
            }

            if (vclass == 25 ||    //MTC大件
                    vclass == 27 ||    //甩挂车
                    vsign == 0)        //ETC大件
            {// MTC大件、甩挂车及ETC大件车
                // 不变
            } else {//	其他货车(含J1、J2集装箱)最大为6轴
                if (feeAxles > 6) {
                    feeAxles = 6;        //其他最大轴数为6轴
                }
            }
        }
        return feeAxles;
    }

    /**
     * 计费车型计算
     *
     * @param vclass - 车种
     * @param vsign  - 车辆标识
     * @param vtype  - 车型
     * @param axles  - 轴数
     * @return - 计费车型
     * 客车等于vtype
     * J1、MTC大件、甩挂车、J2及ETC大件会按轴数升降档、但不小于vtype
     * 其他货车等于vtype
     */
    public static int feeVType(int vclass, int vsign, int vtype, int axles) {
        int feeVType = vtype;
        if (feeVType >= 11) {// 为货车
            int mode = feeVType / 10;
            int feeAxles = feeAxles(vclass, vsign, vtype, axles);
            if (vclass == 24 ||    //J1
                    vclass == 25 ||    //MTC大件
                    vclass == 27 ||    //甩挂车
                    vclass == 28 ||    //J2
                    vsign == 0)        //ETC大件
            {
                if (feeAxles >= 6) {
                    feeVType = mode * 10 + 6;
                } else if (feeAxles == 5) {
                    feeVType = mode * 10 + 5;
                } else if (feeAxles == 4) {
                    feeVType = mode * 10 + 4;
                } else if (feeAxles == 3) {
                    feeVType = mode * 10 + 3;
                }
            }
            if (feeVType < vtype) {
                feeVType = vtype;
            }

        }
        return feeVType;
    }

    /**
     * 获取加收轴数
     * 车型为16、26的甩挂车及大件车，轴数大于6轴需要按轴数加收
     *
     * @param vclass - 车种
     * @param vsign  - 车辆标识
     * @param vtype  - 车型
     * @param axles  - 轴数
     * @return - 加收轴数
     * =0 - 加收轴数为0
     * >0 - 需要加收的轴数
     */
    public static int feeAddAxis(int vclass, int vsign, int vtype, int axles) {
        int res = 0;
        if (feeVType(vclass, vsign, vtype, axles) == 16 || feeVType(vclass, vsign, vtype, axles) == 26) {// 为16及26货车
            if (feeAxles(vclass, vsign, vtype, axles) > 6) {// 只有甩挂车及大件车轴数会>6轴
                res = feeAxles(vclass, vsign, vtype, axles) - 6;
            }
        }
        return res;
    }

    /**
     * 获取车辆限重
     *
     * @param vType
     * @param axis
     * @return - 限重(Kg)
     */
    public static int axisExceedWeight(int vType, int axis) {
        if (isTruck(vType)) {
            if (axis == 2) {
                return 18000;
            } else if (axis == 3) {
                return 25000;
            } else if (axis == 4) {
                return 31000;
            } else if (axis == 5) {
                return 43000;
            } else if (axis >= 6) {
                return 49000;
            }
        }
        return 0;
    }

    /**
     * 计算货车装载率
     *
     * @param vType       - 车型
     * @param axis        - 轴数
     * @param totalWeight - 车货总重(Kg)
     * @return 超载的万分率
     */
    public static int overLoadRate(int vType, int axis, int totalWeight) {
        int xz = axisExceedWeight(vType, axis);
        if (xz > 0 && totalWeight > xz) {// 总重>限重
            return (totalWeight - xz) * 10000 / xz;
        }
        return 0;
    }

    public static String[] array(boolean hasOther) {
        if (hasOther) {
            return new String[]{"99:所有车型", "98:客车", "97:货车", "1:客一", "2:客二", "3:客三", "4:客四", "11:货一", "12:货二", "13:货三", "14:货四", "15:货五", "16:货六", "21:专一", "22:专二", "23:专三", "24:专四", "25:专五", "26:专六"};
        }
        return new String[]{"1:客一", "2:客二", "3:客三", "4:客四", "11:货一", "12:货二", "13:货三", "14:货四", "15:货五", "16:货六", "21:专一", "22:专二", "23:专三", "24:专四", "25:专五", "26:专六"};
    }
}
